package com.example.helloword.background;


import java.util.concurrent.CopyOnWriteArrayList;

public class EventManager {
    private static EventManager instance;
    private final CopyOnWriteArrayList<SourceListener> sourceListeners = new CopyOnWriteArrayList<>();



    private EventManager() {
    }

    public static EventManager getInstance() {
        if (instance == null) {
            synchronized (EventManager.class) {
                if (instance == null) {
                    instance = new EventManager();
                }
            }
        }
        return instance;
    }


    public void addUserListListener(SourceListener sourceListener) {
        if (sourceListener != null) {
            sourceListeners.add(sourceListener);
        }
    }

    public void removeUserListListener(SourceListener sourceListener) {
        if (sourceListener != null) {
            sourceListeners.remove(sourceListener);
        }
    }

    public void removeUserListListeners() {
        sourceListeners.clear();
    }

    public CopyOnWriteArrayList< SourceListener> getSourceListeners() {
        return sourceListeners;
    }


}
